package com.dubbo.provider.config;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * @description: 协议工厂类
 * @author: 石亚宁
 * @create: 2020-05-29 13:55
 **/

public class ProtocolFactory {
	public static Protocol getProtocol(){
		///return getD();
		return getFile();
	}
	private static Protocol getD(){
		String protocolName=System.getProperty("protocolName");
		if (protocolName==null || protocolName.equals("")){
			protocolName="http";
		}
		System.out.println("使用的是："+protocolName+"协议");
		switch (protocolName){
			case "http":

				return new HttpProtocol();

			case "dubbo":
				return new DubboProtocol();
			default:
				return new HttpProtocol();

		}
	}
	private static Protocol getFile(){
		ServiceLoader<Protocol> load = ServiceLoader.load(Protocol.class);
		Iterator<Protocol> iterator = load.iterator();
		return iterator.next();

	}
}
